<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style type="text/css">
input[type="button"] {
	width: 100px
}
</style>

<body>
<div id="div1" style="float:left">
  <select id="sel1" multiple="multiple" style="height:200px;width:100px">
    <option>aaaaaa</option>
    <option>bbbbbb</option>
    <option>cccccc</option>
    <option>dddddd</option>
  </select>
  <br/>
  <input type="button" value="one >>" onClick="leftMove1();"/>
  <br/>
  <input type="button" value="all >>" onClick="leftMoveall();"/>
</div>
<div id="div2">
  <select id="sel2" multiple="multiple" style="height:200px;width:100px">
    <option>111111</option>
    <option>222222</option>
    <option>333333</option>
    <option>444444</option>
  </select>
  <br/>
  <input type="button" value="one <<" onClick="rightMove1();"/>
  <br/>
  <input type="button" value="all <<" onClick="rightMoveall();"/>
</div>
</body>
<script type="text/javascript">
	function leftMove1() {
		var sel1 = document.getElementById("sel1");
		var sel2 = document.getElementById("sel2");
		var opt1array = sel1.getElementsByTagName("option");
		var opt2array = sel2.getElementsByTagName("option");
		for( var i=0; i < opt1array.length; i++ )
		{
			if( opt1array[i].selected == true )
			{
				sel2.appendChild(opt1array[i]);//appendChild是剪切而不是复制
				i--; //由于sel1一个子节点被移除了,所以i必须减去1
			}
		}
	}
	function leftMoveall() {
		var sel1 = document.getElementById("sel1");
		var sel2 = document.getElementById("sel2");
		var opt1array = sel1.getElementsByTagName("option");
		var opt2array = sel2.getElementsByTagName("option");
		for( var i=0; i < opt1array.length; i++ )
		{
			sel2.appendChild(opt1array[i]);//appendChild是剪切而不是复制
			i--; //由于sel1一个子节点被移除了,所以i必须减去1
		}
	}
	
	function rightMove1() {
		var sel1 = document.getElementById("sel1");
		var sel2 = document.getElementById("sel2");
		var opt1array = sel1.getElementsByTagName("option");
		var opt2array = sel2.getElementsByTagName("option");
		for( var i=0; i < opt2array.length; i++ )
		{
			if( opt2array[i].selected == true )
			{
				sel1.appendChild(opt2array[i]);//appendChild是剪切而不是复制
				i--; //由于sel2一个子节点被移除了,所以i必须减去1
			}
		}
		
	}
	function rightMoveall() {
		var sel1 = document.getElementById("sel1");
		var sel2 = document.getElementById("sel2");
		var opt1array = sel1.getElementsByTagName("option");
		var opt2array = sel2.getElementsByTagName("option");
		for( var i=0; i < opt2array.length; i++ )
		{
			sel1.appendChild(opt2array[i]);//appendChild是剪切而不是复制
			i--; //由于sel2一个子节点被移除了,所以i必须减去1
		}		
	}
</script>
</html>
